// 导入需要的config和request
import confing from '../config/config.js';
import request from '../util/request.js';
// 申明请求对象
const iqcRequst = {
    BASE_URL: confing.QC_URL + "/iqc",
    //新增请求

    //多选删除按钮
    deletes(iqcIds, callback) {
        //拼接URL
        let url = this.BASE_URL + "/deletes?t=1";
        if (iqcIds != undefined) {
            iqcIds.forEach(iqcId => {
                url += "&iqcId=" + iqcId;
            })
            request.delete(url, callback);
        }
    },
    //删除信息
    delete(iqcId, callback) {
        request.delete(this.BASE_URL + "/" + iqcId, callback);
    },
    //编辑信息
    edit(iqc, callback) {
        if (iqc != undefined && iqc.iqcId != undefined) {
            request.put(this.BASE_URL + "/update", iqc, callback);
        }

    },

    //根据id查询信息
    get(iqcId, callback) {
        if (iqcId) {
            // 准备url
            let url = this.BASE_URL + "/get?iqcId=" + iqcId;
            request.get(url, callback);
        }

    },
    //保存信息
    save(iqc, callback) {
        if (iqc) {
            request.post(this.BASE_URL + "/save", iqc, callback);
        }
    },
    // 请求的API
    list(page = 1, limit = 10, iqc, callbcak) {
        // url
        let url = this.BASE_URL + "/list?page=" + page +
            "&limit=" + limit;
        if (iqc) {
            if (iqc.iqcCode) {
                url += "&iqcCode=" + iqc.iqcCode;
            }
            if (iqc.vendorName) {
                url += "&vendorName=" + iqc.vendorName;
            }
            if (iqc.vendorBatch) {
                url += "&vendorBatch=" + iqc.vendorBatch;
            }
            if (iqc.itemCode) {
                url += "&itemCode=" + iqc.itemCode;
            }
            if (iqc.itemName) {
                url += "&itemName=" + iqc.itemName;
            }
            if (iqc.checkResult) {
                url += "&checkResult=" + iqc.checkResult;
            }
            if (iqc.reciveDate) {
                url += "&reciveDate=" + iqc.reciveDate;
            }
            if (iqc.inspectDate) {
                url += "&inspectDate=" + iqc.inspectDate;
            }
            if (iqc.inspecor) {
                url += "&inspecor=" + iqc.inspecor;
            }

        }
        // 发送请求
        request.get(url, callbcak);
    }

}

// 将dictRequest暴漏出去
export default iqcRequst;